<template>
  <div class="basic_info">
    <div>
      <div class="info_operation_btn">
        <p>产品动态</p>
        <div>
          <input v-model="queryData.keywords" placeholder="输入关键字查询" />
          <el-button type="primary" @click="onQuery">搜索</el-button>
        </div>
      </div>
      <el-empty description="暂无数据" v-if="total === 0"></el-empty>
      <div class="info_content_div" v-else>
        <div @click="toDetails(item)" v-for="(item, index) in listData" :key="index">
          <p class="p_title">{{ item.titile }}</p>
          <div class="div_content">
            <div class="div_abstract">{{ item.msgAbstract }}</div>
            <div class="div_time">
              <span>{{ formatTime(item) }}</span>
            </div>
          </div>
        </div>
      </div>
      <div class="table_pagination">
        <div class="pagination_div">
          <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
            :current-page="queryData.pageNo" :page-sizes="[20, 50, 100, 200]" :page-size="queryData.pageSize"
            layout="jumper, prev, pager,next, sizes" :total="total">
          </el-pagination>
        </div>
      </div>
    </div>
    <!-- 消息详情页面 -->
    <DialogNotice ref="dialogNotice"></DialogNotice>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { getAction } from '@/api/manage'
import { formatTime } from '@/utils/index'
// 消息详情页面
import DialogNotice from '../components/dialogNotice'
export default {
  name: 'productDynamics',
  components: {
    DialogNotice,
  },
  computed: {
    ...mapGetters(['name']),
  },
  created() {
    this.getNotice()
  },
  data() {
    return {
      listData: [],
      // 查询条件数据
      queryData: {
        keywords: '',
        msgCategory: '1', // 1:通知公告,产品动态 2:系统消息
        pageSize: 20, //每页的数据条数
        pageNo: 1, //默认开始页面
      },
      total: 0, // 总数
    }
  },
  methods: {
    //   搜索
    onQuery() {
      this.queryData.pageNo = 1
      this.getNotice()
    },
    // 获取消息列表
    getNotice() {
      let data = { ...this.queryData }
      getAction('/sys/annountCement/getNotice', data).then((res) => {
        if (res.code === 200) {
          this.total = res.result.total
          this.listData = res.result.records || []
        }
      })
    },
    // 跳转至详情
    toDetails(item) {
      this.$refs.dialogNotice.show(item)
    },
    // 获取每页几条数据
    handleSizeChange(val) {
      this.queryData.pageSize = val
      this.getNotice()
    },
    // 获取当前第几页
    handleCurrentChange(val) {
      this.queryData.pageNo = val
      this.getNotice()
    },
    formatTime(val) {
      if (!val.sendTime) {
        return val.sendTime
      }
      return formatTime(Date.parse(val.sendTime))
    },
  },
}
</script>

<style lang="scss" scoped>
.basic_info {
  width: 100%;
  height: calc(100vh - 110px);
  background: #f0f2f5;
  box-sizing: border-box;
  padding: 0 8px 8px;
  display: flex;
  flex-direction: column;

  >div {
    height: 100%;
    background: #fff;
    padding: 0 38px;

    &:last-child {
      height: 0px;
    }
  }
}

.info_operation_btn {
  width: 100%;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #eeeeee;

  >p {
    margin: 0;
    font-size: 16px;
    font-family: PingFang SC;
    font-weight: 600;
    color: #1b94fb;
  }

  >div {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex: 1;

    >div {
      font-size: 12px;
      font-family: PingFang SC;
      font-weight: 400;
      color: #666;
      margin-right: 5px;
    }

    ::v-deep .el-select {
      width: 120px;
      height: 30px;
      box-sizing: border-box;
      border-radius: 4px;

      .el-input {
        .el-input__inner {
          height: 30px;
          border-color: #e3e3e3;
          font-size: 12px;
          padding-left: 8px;
        }

        .el-input__suffix {
          height: 30px;
          display: flex;
          align-items: center;
        }
      }
    }

    input {
      width: 190px;
      height: 30px;
      background: #fff;
      border: 1px solid #e3e3e3;
      border-radius: 5px;
      font-size: 12px;
      color: #666;
      box-sizing: border-box;
      padding: 0 0.150009rem;
      margin: 0 5px 0 0.375023rem;

      &:focus {
        outline: none;
        border-color: #1890ff;
      }
    }

    ::v-deep .el-button {
      width: 60px;
      height: 30px;
      background: #1a93fa;
      border: none;
      border-radius: 5px;
      display: flex;
      align-items: center;
      justify-content: center;
    }
  }
}

.el-empty {
  width: 100%;
  height: calc(100% - 50px - 60px);
  box-sizing: border-box;
  overflow: auto;
}

.info_content_div {
  width: 100%;
  height: calc(100% - 50px - 60px);
  box-sizing: border-box;
  overflow: auto;

  >div {
    width: 100%;
    box-sizing: border-box;
    padding: 22px 0 10px 0;
    display: flex;
    flex-direction: column;
    border-bottom: 1px solid #eeeeee;

    &:hover {
      background: #e3f6ff;
    }
  }
}

.p_title {
  margin: 0;
  margin-bottom: 9px;
  font-size: 16px;
  font-family: PingFang SC-Regular, PingFang SC;
  font-weight: 400;
  line-height: 22px;
  color: rgba(0, 0, 0, 0.65);
}

.div_content {
  display: flex;
  justify-content: space-between;
  margin-right: 10px;

  .div_abstract {
    width: calc(100% - 120px);
    font-size: 12px;
    font-family: PingFangSC-Regular-, PingFangSC-Regular;
    font-weight: normal;
    color: rgba(0, 0, 0, 0.45);
    line-height: 20px;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
  }

  .div_time {
    display: flex;
    align-self: flex-end;

    >span {
      font-size: 12px;
      font-family: HelveticaNeue-, HelveticaNeue;
      line-height: 20px;
      color: rgba(0, 0, 0, 0.45);
      font-weight: normal;
    }
  }
}

.table_pagination {
  width: 100%;
  height: 60px;
  box-sizing: border-box;
  padding: 8px 0;
  display: flex;

  .pagination_div {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: flex-end;

    ::v-deep .el-pagination {
      padding: 0;
      height: 30px;

      .el-pagination__sizes {
        margin: 0;

        .el-input {
          margin-right: 0;
        }
      }
    }
  }
}
</style>
